package v9.assist.analyst

import android.graphics.Bitmap
import kotlinx.coroutines.script.Block
import kotlinx.coroutines.script.TARGET
import kotlinx.coroutines.script.analysis.Analysis
import kotlinx.coroutines.script.SMapBase.hitBox
import kotlinx.coroutines.script.SMapBase.hitDeathRed
import kotlinx.coroutines.script.SMapBase.hitEquipO
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyBlue
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyYellow
import kotlinx.coroutines.script.SMapBase.hitTeammate
import kotlinx.coroutines.script.tes.ColorDiffer
import kotlinx.coroutines.script.tes.printLog
import kotlinx.coroutines.script.tes.pt
import kotlinx.coroutines.script.tes.rgb
import kotlinx.coroutines.script.tes.shake
import v9.assist.script.xBossBesideTs
import v9.assist.script.xLastAtkTs
import v9.assist.script.xLastPetBlacksmithTs
import v9.assist.script.xLastSceneEnterTs
import v9.assist.script.xLastUnknownTs

private val hitRoad by lazy {
    val out = mutableSetOf<ColorDiffer>()
    out.addAll(setOf(0xff4F3B30.toInt().rgb(24),)) // 起点区域
    out.addAll(setOf(0xff52382c.toInt().rgb(24),)) // 起点区域 edge大点保证路线完整性
    out.addAll(setOf(0xff45362a.toInt().rgb(24),)) // p2起点
    out.addAll(hitEquipO)
    out.addAll(hitBox)
    out.addAll(hitDeathRed)
    out.addAll(hitTeammate)
    out.addAll(hitSMapEnemyYellow)
    out.addAll(hitSMapEnemyBlue)
    out
}

var anaPathfindingModeRHBeP2Ts = 0L
var anaPathfindingModeRH = MODE_PATHFINDING_P1 // p1 p2
var anaLastSMapRHFeature1Ts = 0L // P2起点
var anaLastSMapRHFeature2Ts = 0L // 电梯
var anaLastSMapRHFeature3Ts = 0L // Boss入口
var anaLastSMapRHFeature4Ts = 0L //
var anaLastSMapRHFeature5Ts = 0L // Boss入口2
var anaLastSMapRHFeature6Ts = 0L //
var anaLastSMapRHFeature7Ts = 0L // 直通
var anaLastSMapRHFeature8Ts = 0L // 副本起点
var anaLastSMapRHFeature9Ts = 0L // 电梯强拉
var anaLastSMapRHFeature10Ts = 0L // 最终Boss2阶段
var anaLastSMapRHFeature11Ts = 0L // P1刚落地跳崖

fun rasterizeMapRH(ss: Bitmap): Array<IntArray> {
    return rasterizeMap(ss, hitRoad, emptyPrimaryRoad, filterEnemyY = false, filterRedDot = true)
}

fun analysisMapRH(ss: Bitmap) {
    analysisMapElements(ss)
    // 踢掉红色点
    val returnMapArray = rasterizeMapRH(ss)

    if (blockEliteEnemyBoss != null && mapEnemyList.isNotEmpty()) {
        // 优先Boss
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to boss" }
        lastSMapTargetToBossTs = System.currentTimeMillis()
        if (mapElementDistance(blockEliteEnemyBoss) < 30.pt) xBossBesideTs = System.currentTimeMillis()
    } else if (mapEnemyList.isNotEmpty()
        && System.currentTimeMillis() - anaLastSMapRHFeature4Ts > 10000 // 在副本外面的误判导致没有开始
        && System.currentTimeMillis() - anaLastPageSceneEnterTs > 10000 // 刚开局就需要
        && System.currentTimeMillis() - anaLastSceneSettleTs > 20000
        && System.currentTimeMillis() - xLastUnknownTs > 10000
        && (mapEnemyList.map { it.first }.average() > selfInSmallMap.x - smallMap.left - 30.pt) // 全屏幕也就140.pt左右
        && !bsSceneSettle && !bsSceneSettleBlacksmith) {
        // 优先敌人
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to elite enemy" }
    } else if (bsSceneSettleBlacksmith && mapBlacksmithList.isNotEmpty()) {
        mapTargetList.add(mapBlacksmithList.random())
        printLog { "analyst target to blacksmith" }
    } else if (bsSceneSettle && mapBlueDoorList.isNotEmpty()) {
        mapTargetList.add(mapBlueDoorList.random())
        printLog { "analyst target to blueDoor" }
    } else if (anaPathfindingModeRH == MODE_PATHFINDING_P1) {
        (mapBottomNotArrived.minByOrNull { it.second })?.also {
            mapTargetList.add(it)
            printLog { "analyst target to p1 bottom" }
        }
        if (mapTargetList.isEmpty()) {
            (mapLeftNotArrived.filter { it.second > 80.pt }.minByOrNull { it.second })?.also {
                mapTargetList.add(it)
                printLog { "analyst target to p1 left (filter left-top)" }
            }
        }
        if (mapTargetList.isEmpty()) {
            (mapSampleArrived.maxByOrNull { it.second })?.also {
                mapTargetList.add(it)
                printLog { "analyst target to p1 bottom by sample" }
            }
        }
        if (mapTargetList.isEmpty()) {
            mapSampleArrived.randomOrNull()?.also {
                mapTargetList.add(it)
                printLog { "analyst target to p1 sample random" }
            }
        }
    } else if (anaPathfindingModeRH == MODE_PATHFINDING_P2
        && System.currentTimeMillis() - anaPathfindingModeRHBeP2Ts > 30000
        && (mapRightNotArrived.size > 0 && mapTopNotArrived.map { it.first }.average() < 100.pt)) {
        (mapTopNotArrived.minByOrNull { it.second } ?: mapTopNotArrived.random()).also {
            mapTargetList.add(it)
            printLog { "analyst target to p2 right -> left top" }
        }
    } else if (anaPathfindingModeRH == MODE_PATHFINDING_P2 && mapRightNotArrived.isNotEmpty()) {
        (mapRightNotArrived.minByOrNull { it.second } ?: mapRightNotArrived.random()).also {
            mapTargetList.add(it)
            printLog { "analyst target to p2 right" }
        }
    } else if (anaPathfindingModeRH == MODE_PATHFINDING_P2 && mapTopNotArrived.isNotEmpty()) {
        (mapTopNotArrived.minByOrNull { it.second } ?: mapTopNotArrived.random()).also {
            mapTargetList.add(it)
            printLog { "analyst target to p2 top" }
        }
    } else if (anaPathfindingModeRH == MODE_PATHFINDING_P2 && mapSampleArrived.isNotEmpty()) {
        if (blockEliteEnemyBoss != null) {
            // 最后的boss由于路线问题 empty里面是 空.这里强控制去左上角
            mapSampleArrived
                .minByOrNull { it.first + it.second }?.also {
                    mapTargetList.add(it)
                    printLog { "analyst target to p2 sample left top boss" }
                }
        } else {
            mapSampleArrived
                .filter { it.second <= (selfInSmallMap.y - smallMap.top) }
                .randomOrNull()?.also {
                    mapTargetList.add(it)
                    printLog { "analyst target to p2 sample top" }
                }
        }
    }

    if (mapTargetList.isNotEmpty()) {
        val target = mapTargetList.random()
        returnMapArray[target.first][target.second] = TARGET
    }

    angleByRoad = analysisRasterizeMap(returnMapArray)
    angleByRoad = angleSpecialAdjust(angleByRoad ?: (if (anaPathfindingModeRH == MODE_PATHFINDING_P2) 85.shake(10) else 260.shake(10)))

    // map feature
    analysisMapRHIsStartPoint(ss)
    if ((blockBlueDoor == null || blockBlacksmith == null)
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000) {
        printLog { "analystRH $mapSimpleStatus" }
        if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.56 .. 0.72
            && lastMapBottomP == null
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.14 .. 0.26
        ) {
            //  [上,0s,0.6300962,c:37][下,67s,c:0][左,46s,c:0][右,0s,0.21184371,c:21]][Road,c:12]
            //  [上,0s,0.6501774,c:43][下,26s,c:0][左,5s,c:0][右,0s,0.19373219,c:18]][Road,c:12]
            //  [上,0s,0.60134184,c:48][下,18s,c:0][左,12s,c:0][右,0s,0.17948718,c:16]][Road,c:12]
            printLog { "analystRH 节点.P2起点" }
            anaPathfindingModeRH = MODE_PATHFINDING_P2
            anaPathfindingModeRHBeP2Ts = System.currentTimeMillis()
            anaLastSMapRHFeature1Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && (lastMapLeftP ?: -1f) in 0.42 .. 0.68
            && (lastMapRightP ?: -1f) in 0.40 .. 0.52
            && System.currentTimeMillis() - anaLastSMapRHFeature4Ts > 6000
            && System.currentTimeMillis() - xLastAtkTs > 3000
        ) {
            //  [上,15s,c:0][下,20s,c:0][左,0s,0.51282054,c:12][右,0s,0.4683258,c:17]][Road,c:9]
            //  [上,11s,c:0][下,0s,0.17118645,c:35][左,0s,0.67291254,c:39][右,0s,0.4871795,c:16]][Road,c:15]
            //  反 [上,22s,c:0][下,0s,0.025423728,c:1][左,0s,0.74542123,c:21][右,0s,0.61538464,c:12]][Road,c:10]
            printLog { "analystRH 节点.电梯" }
            anaPathfindingModeRH = MODE_PATHFINDING_P2 // 拉过来的人状态修正
            anaPathfindingModeRHBeP2Ts = System.currentTimeMillis()
            anaLastSMapRHFeature2Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.21 .. 0.29
            && lastMapBottomP == null
            && lastMapLeftP == null
            && lastMapRightP == null
        ) {
            // [上,0s,0.25825155,c:19][下,2s,c:0][左,18s,c:0][右,51s,c:0]][Road,c:7]
            printLog { "analystRH 节点.Boss入口" }
            anaPathfindingModeRH = MODE_PATHFINDING_P2 //
            anaPathfindingModeRHBeP2Ts = System.currentTimeMillis()
            anaLastSMapRHFeature3Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.21 .. 0.54
            && (lastMapRightP ?: -1f) in 0.50 .. 0.94
            && System.currentTimeMillis() - anaLastSMapRHFeature2Ts > 12000
            && System.currentTimeMillis() - anaLastSMapRHFeature8Ts > 12000
            && System.currentTimeMillis() - anaLastSMapRHFeature9Ts > 12000
            && System.currentTimeMillis() - anaLastPageAtvTs > 12000 // 刚跳崖活动页面后触发
            && System.currentTimeMillis() - anaPathfindingModeRHBeP2Ts > 40000
        ) {
            // [上,5s,c:0][下,0s,0.45658085,c:27][左,17s,c:0][右,0s,0.9118104,c:11]][Road,c:38]
            // [上,26s,c:0][下,0s,0.39077213,c:18][左,6s,c:0][右,0s,0.86068374,c:15]][Road,c:12]
            // [上,8s,c:0][下,0s,0.26862437,c:43][左,0s,0.6135531,c:35][右,0s,0.73964494,c:26]][Road,c:13]
            // [上,9s,c:0][下,0s,0.5046225,c:11][左,0s,0.4148718,c:25][右,0s,0.52981514,c:43]][Road,c:18]
            printLog { "analystRH 节点.副本外入口" }
            anaLastSMapRHFeature4Ts = System.currentTimeMillis()
            anaClearSceneSettle() // [重要.结算失败.角色跑出去了]重置掉结算状态
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.15 .. 0.25
            && (lastMapBottomP ?: -1f) in 0.70 .. 0.80
            && lastMapLeftP == null
            && lastMapRightP == null
            && System.currentTimeMillis() - anaLastSceneSettleTs > 20000
        ) {
            printLog { "analystRH 节点.Boss入口2" }
            // [上,0s,0.20750605,c:35][下,0s,0.75741524,c:16][左,26s,c:0][右,51s,c:0]][Road,c:6]
            // [上,0s,0.20750605,c:35][下,0s,0.75741524,c:16][左,27s,c:0][右,53s,c:0]][Road,c:6]
            anaPathfindingModeRH = MODE_PATHFINDING_P2 //
            anaPathfindingModeRHBeP2Ts = System.currentTimeMillis()
            anaLastSMapRHFeature5Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.32 .. 0.48
            && (lastMapLeftP ?: -1f) in 0.72 .. 0.86
            && lastMapRightP == null
            && System.currentTimeMillis() - lastBlueDoorTs < 2000
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 12000
        ) {
            printLog { "analystRH 节点.直通" }
            // [上,1105s,c:0][下,0s,0.37538794,c:71][左,0s,0.8101343,c:14][右,459s,c:0]][Road,c:19]
            // [上,1101s,c:0][下,0s,0.4210988,c:58][左,0s,0.8101343,c:14][右,455s,c:0]][Road,c:18]
            // 高了 反 [上,1738380646s,c:0][下,0s,0.42782485,c:80][左,0s,0.8797314,c:14][右,1738380646s,c:0]][Road,c:16]
            anaLastSMapRHFeature7Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && lastMapBottomP == null
            && (lastMapLeftP ?: -1f) in 0.56 .. 0.82
            && (lastMapRightP ?: -1f) in 0.52 .. 0.70
            && System.currentTimeMillis() - xLastAtkTs > 3000
        ) {
            // [上,1738480265s,c:0][下,1738480265s,c:0][左,0s,0.767094,c:32][右,0s,0.67948717,c:8]][Road,c:29]
            // [上,1738480299s,c:0][下,1738480299s,c:0][左,0s,0.60636276,c:18][右,0s,0.55982906,c:8]][Road,c:24]
            printLog { "analystRH 节点.电梯强拉" }
            anaPathfindingModeRH = MODE_PATHFINDING_P2 //
            anaPathfindingModeRHBeP2Ts = System.currentTimeMillis()
            anaLastSMapRHFeature9Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
            && lastMapBottomP == null
            && lastMapLeftP == null
            && lastMapRightP == null
            && System.currentTimeMillis() - xLastAtkTs > 3000 // 最后的boss那里 往左上角走
            && System.currentTimeMillis() - lastBlueDoorTs > 3000 // 避免开局触发A
            && System.currentTimeMillis() - xLastUnknownTs > 3000 // 避免开局触发B
        ) {
            // [上,1738480265s,c:0][下,1738480265s,c:0][左,0s,0.767094,c:32][右,0s,0.67948717,c:8]][Road,c:29]
            // [上,1738480299s,c:0][下,1738480299s,c:0][左,0s,0.60636276,c:18][右,0s,0.55982906,c:8]][Road,c:24]
            printLog { "analystRH 节点.最终Boss2阶段" }
            anaLastSMapRHFeature10Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.06 .. 0.18
            && (lastMapLeftP == null || (lastMapLeftP ?: -1f) in 0.83 .. 0.90)
            && (lastMapRightP ?: -1f) in 0.23 .. 0.33
            && System.currentTimeMillis() - lastBlueDoorTs > 3000 // 避免开局触发A
            && System.currentTimeMillis() - xLastUnknownTs > 3000 // 避免开局触发B
        ) {
            // [上,1746926190s,c:0][下,0s,0.097457625,c:16][左,0s,0.8632479,c:8][右,0s,0.2863248,c:22]][Road,c:22]
            // [上,1s,c:0][下,0s,0.1539548,c:18][左,4s,c:0][右,0s,0.26495728,c:24]][Road,c:22]
            // [上,3s,c:0][下,0s,0.10674993,c:19][左,0s,0.879867,c:9][右,0s,0.25938314,c:23]][Road,c:24]
            // [上,23s,c:0][下,0s,0.097457625,c:18][左,0s,0.87927353,c:4][右,0s,0.30211818,c:23]][Road,c:23]
            printLog { "analystRH 节点.P1跳崖落地点" } // 没到P2前误判了P2所以回到这里了
            anaLastSMapRHFeature11Ts = System.currentTimeMillis()
        }
    }

    if (System.currentTimeMillis() - anaLastPageSceneEnterTs > 8000
        && System.currentTimeMillis() - xLastUnknownTs > 8000
        && System.currentTimeMillis() - anaLastHasEnemyNameTs > 4000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 4000
        && System.currentTimeMillis() - anaLastSMapRHFeature4Ts > 6000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        // && blockBlueDoor != null
        && blockBlacksmith != null
        && !bsSceneSettle && !bsSceneSettleBlacksmith
        && simpleAssertSceneCompleted(blockBlueDoor, blockBlacksmith)) {
        printLog { "analyst scene completed count $anaCounterSceneSettle" }
        anaCounterSceneSettle++
        if (anaCounterSceneSettle > 1) {
            printLog { "analyst scene completed" }
            anaMarkSceneSettle()
        }
    }
    if (System.currentTimeMillis() - lastBlueDoorTs > 3000
        && System.currentTimeMillis() - lastBlacksmithTs > 3000) {
        anaCounterSceneSettle = 0
    }
}

val cRHP1StartA1 by lazy { Block("融魂起点黑红下1", selfInSmallMap.x - 40.pt, selfInSmallMap.y + 40.pt, 40.pt, 20.pt) }
val cRHP1StartA2 by lazy { Block("融魂起点黑红下2", selfInSmallMap.x - 30.pt, selfInSmallMap.y + 60.pt, 40.pt, 20.pt) }
val cRHP1StartA3 by lazy { Block("融魂起点黑红上3", selfInSmallMap.x + 40.pt, selfInSmallMap.y - 50.pt, 30.pt, 20.pt) }
val cRHP1StartA4 by lazy { Block("融魂起点黑红上4", selfInSmallMap.x + 60.pt, selfInSmallMap.y - 70.pt, 30.pt, 20.pt) }

private val cRHP1StartB1 by lazy { Block("融魂起点检测B1", selfInSmallMap.x + 2.pt, selfInSmallMap.y + 12.pt, 20.pt, 20.pt) }
private val cRHP1StartB2 by lazy { Block("融魂起点检测B2", selfInSmallMap.x - 84.pt, selfInSmallMap.y + 84.pt, 20.pt, 20.pt) }
private val cRHP1StartB3 by lazy { Block("融魂起点检测B3", selfInSmallMap.x - 64.pt, selfInSmallMap.y + 84.pt, 20.pt, 20.pt) }
private val cRHP1StartB4 by lazy { Block("融魂起点检测B4", selfInSmallMap.x + 145.pt, selfInSmallMap.y + 59.pt, 20.pt, 20.pt) }
private val hitStartRoad by lazy { setOf(0xff4C3A30.toInt().rgb(12),) }

fun analysisMapRHIsStartPoint(ss: Bitmap): Boolean {
    if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
        && blockBlacksmith == null
        && blockBlueDoor != null
//        && System.currentTimeMillis() - lastBlueDoorTs < 3000
    ) {
        var hitPart = 0
        // [rhSpC5] 0.6666667 hitCount 24 total 36
        // [rhSpC6] 0.7222222 hitCount 26 total 36
        if (!Analysis.hit(ss, cRHP1StartA1, hitStartRoad, 5.pt, 0.1f, )) hitPart++ // , "rhSpC1" // 0.5
        if (!Analysis.hit(ss, cRHP1StartA2, hitStartRoad, 5.pt, 0.1f,)) hitPart++ // , "rhSpC2" // 0.5
        if (!Analysis.hit(ss, cRHP1StartA3, hitStartRoad, 5.pt, 0.1f,)) hitPart++ // , "rhSpC3" // 0.5
        if (!Analysis.hit(ss, cRHP1StartA4, hitStartRoad, 5.pt, 0.1f,)) hitPart++ // , "rhSpC4" // 0.5
        if (Analysis.hit(ss, cRHP1StartB2, hitStartRoad, 4.pt, 0.5f,  )) hitPart++ // , "rhSpC5"
        if (Analysis.hit(ss, cRHP1StartB3, hitStartRoad, 4.pt, 0.5f, ))hitPart++
        if (hitPart >= 6) {
            printLog { "analystRH 节点.融魂路线是起点C" }
            anaPathfindingModeRH = MODE_PATHFINDING_P1 //
            anaLastSMapRHFeature8Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
    }
    if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
        && blockBlacksmith == null
//        && blockBlueDoor != null
    ) {
        var hitPart = 0
        // hit [rhB1] 0.9444444 hitCount 34 total 36
        // hit [rhB2] 0.6666667 hitCount 24 total 36
        // hit [rhB3] 0.7222222 hitCount 26 total 36
        // hit [rhB4] 0.6666667 hitCount 24 total 36
        if (Analysis.hit(ss, cRHP1StartB1, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "rhB1"
        if (Analysis.hit(ss, cRHP1StartB2, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "rhB2"
        if (Analysis.hit(ss, cRHP1StartB3, hitStartRoad, 4.pt, 0.5f, )) hitPart++ // , "rhB3"
        if (Analysis.hit(ss, cRHP1StartB4, hitStartRoad, 4.pt, 0.5f, )) hitPart++ //  "rhB4"
        if (hitPart >= 4) {
            printLog { "analystRH 节点.融魂路线是起点B" }
            anaPathfindingModeRH = MODE_PATHFINDING_P1 //
            anaLastSMapRHFeature8Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
    }

    if (System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        && System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
        && lastMapTopP == null
        && (lastMapBottomP ?: -1f) in 0.59 .. 0.71
        && lastMapLeftP == null
        && lastMapRightP == null
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 12000
        && blockBlacksmith == null
        && blockBlueDoor != null
//        && System.currentTimeMillis() - lastBlueDoorTs < 3000
    ) {
        // [上,1745592103s,c:0][下,0s,0.611425,c:18][左,1745592103s,c:0][右,1745592103s,c:0]][Road,c:6]
        // [上,1738380690s,c:0][下,0s,0.67966104,c:20][左,7s,c:0][右,1738380690s,c:0]][Road,c:5]
        // [上,1738380707s,c:0][下,0s,0.6890772,c:15][左,23s,c:0][右,1738380707s,c:0]][Road,c:5]
        // [上,1746170359s,c:0][下,0s,0.6392252,c:14][左,1746170359s,c:0][右,1746170359s,c:0]][Road,c:6]
        printLog { "analystRH 节点.融魂路线是起点A" }
        anaPathfindingModeRH = MODE_PATHFINDING_P1 //
        anaLastSMapRHFeature8Ts = System.currentTimeMillis()
        anaClearSceneSettle()
        return true
    }
    return false
}

private fun simpleAssertSceneCompleted(blueDoor: Block?, blacksmith: Block?): Boolean {
    return blacksmith != null
}

private fun angleSpecialAdjust(angle: Int): Int {
    if (angle in 80 .. 260) {
        if (System.currentTimeMillis() - xLastAtkTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyTs > 5000
            && System.currentTimeMillis() - anaLastSMapRHFeature1Ts > 20000 // 地图特征 条件
            && System.currentTimeMillis() - anaLastSMapRHFeature2Ts > 20000
            && System.currentTimeMillis() - anaLastSMapRHFeature3Ts > 20000
            && System.currentTimeMillis() - anaLastSMapRHFeature5Ts > 150000 //150s
            && System.currentTimeMillis() - anaLastSMapRHFeature7Ts > 20000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000
            && System.currentTimeMillis() - xLastUnknownTs < 20000
            && System.currentTimeMillis() - xLastPetBlacksmithTs > 20000
            && System.currentTimeMillis() - anaLastPageAtvTs > 20000 // 跳崖活动页触发屏蔽.融魂特有
            ) {
            printLog { "analystRH angleSpecialAdjust $angle to 0" }
            return 0
        }
    }
    return angle
}